package com.lanou.pianke.articlecategory.web.controller;

import com.lanou.pianke.articlecategory.entity.ACategory;
import com.lanou.pianke.articlecategory.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/article")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/category")
    public List<ACategory> showCategory(){

        List<Integer> acids = categoryService.selectAcid();

        for (int i = 0; i < acids.size(); i++) {
            Integer acid = acids.get(i);
            Integer articleCount = categoryService.selectArticleCount(acid);
            categoryService.updateArticleCount(acid,articleCount);
        }

        return categoryService.selectCategory();

    }


}
